/**
 * Transaction object that monitor a transaction
 * 
 * @author guillaumeR
 */

package gicom.transaction;

import java.util.ArrayList;
import java.util.List;

import gicom.generated.transaction.LocalTransactionManager;
import gicom.generated.transaction.State;
import gicom.generated.transaction.Vote;

public class Transaction {

    /**
     * State of the transaction
     */
    private State state;

    /**
     * voteState of the transaction
     */
    private Vote voteState;

    /**
     * List of LocalTransactionManagers enrolled into the transaction
     */
    private List<LocalTransactionManager> ltms;

    /**
     * 
     */
    private final int transactionNumber;

    /**
     * Constructor of the Transaction. Set the transaction state to INITIAL
     */
    public Transaction(int transactionNumber) {
	this.transactionNumber = transactionNumber;
	this.state = State.INITIAL;
	ltms = new ArrayList<LocalTransactionManager>();
    }

    /**
     * Get the state of the transaction
     * 
     * @return the current state of the transaction
     */
    public State getState() {
	return state;
    }

    /**
     * Set the current state of the transaction
     * 
     * @param state
     *                state to set for the transaction
     */
    public void setState(State state) {
	this.state = state;
    }

    /**
     * Get the current vote state of the transaction
     * 
     * @return the current vote state of the transaction
     */
    public Vote getVoteState() {
	return voteState;
    }

    /**
     * Set the current vote state of the transaction
     * 
     * @param voteState
     *                vote state to set for the transaction
     */
    public void setVoteState(Vote voteState) {
	this.voteState = voteState;
    }

    /**
     * Add a LocalTransactionManager to the list of enrolled LTM for the
     * transaction
     * 
     * @param ltm
     *                the LocalTransactionManager to add for the transaction
     */
    public void addLTM(LocalTransactionManager ltm) {
	this.ltms.add(ltm);
    }

    /**
     * Get the list of LocalTransactionManager enrolled in the transaction
     * 
     * @return the list of LocalTransactionManager enrolled in the transaction
     */
    public List<LocalTransactionManager> getLtms() {
	return ltms;
    }

    /**
     * 
     * @return the number of the transaction
     */
    public int getTransactionNumber() {
        return transactionNumber;
    }
    
    

}
